package me.samlss.lighter.parameter;

import me.samlss.lighter.Lighter;
import me.samlss.lighter.shape.LighterShape;
import ohos.aafwk.ability.Ability;
import ohos.agp.animation.AnimatorValue;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.utils.RectFloat;
import ohos.app.Context;

/**
 * @author: zhu_zhonglin
 * @time: 2021/4/25
 */
public class LighterParameter {
    /**
     * 高亮ViewId
     */
    private int highlightedViewId;
    /**
     * 高亮View组件
     */
    private Component highlightedView;
    /**
     * 高亮View显示区域
     */
    private RectFloat highlightedViewRect;
    /**
     * tips布局Id
     */
    private int tipLayoutId;
    /**
     * tips布局View
     */
    private Component tipView;
    /**
     * lighter形状
     */
    private LighterShape lighterShape;
    /**
     * shape X轴偏移量
     */
    private float shapeXOffset;
    /**
     * shape y轴偏移量
     */
    private float shapeYOffset;
    /**
     * tipView 相对位置
     */
    private int tipViewRelativeDirection;
    /**
     * tips展示偏移量
     */
    private MarginOffset tipViewRelativeMarginOffset;
    /**
     * tips展示动画
     */
    private AnimatorValue tipViewDisplayAnimation;
    /**
     * 自动垂直匹配
     */
    private boolean autoVerticalFixed;

    private  LighterParameter(){
    }

    /**
     * 垂直方向自动适配
     * @param autoVerticalFixed autoVerticalFixed
     */
    public void setAutoVerticalFixed(boolean autoVerticalFixed) {
        this.autoVerticalFixed = autoVerticalFixed;
    }

    /**
     * 设置 highlightedViewId
     * @param highlightedViewId highlightedViewId
     */
    public void setHighlightedViewId(int highlightedViewId) {
        this.highlightedViewId = highlightedViewId;
    }

    /**
     * Set the view that will be highlighted.
     *
     * @param highlightedView The highlighted view.
     * */
    public void setHighlightedView(Component highlightedView) {
        this.highlightedView = highlightedView;
    }

    /**
     * Set the layout id of the tip layout. <br>
     *
     * Will call {@link LayoutScatter#getInstance(Context)#parse(int, ComponentContainer, boolean)} to create the
     * tip layout. <br>
     *
     * Will attached to {@link me.samlss.lighter.view.LighterView}
     *
     * @param tipLayoutId The layout id of tip.
     * */
    public void setTipLayoutId(int tipLayoutId) {
        this.tipLayoutId = tipLayoutId;
    }

    /**
     * Set the tip view
     *
     * Will attached to {@link me.samlss.lighter.view.LighterView}
     * @param tipView The tip view.
     * */
    public void setTipView(Component tipView) {
        this.tipView = tipView;
    }

    /**
     * Set the shape of the wrapped highlight view
     *
     * @param lighterShape The highlighted shape.
     * */
    public void setLighterShape(LighterShape lighterShape) {
        this.lighterShape = lighterShape;
    }

    /**
     * Set the x-axis offset of the shape rect({@link LighterShape#setViewRect(RectFloat)}), default is 0  <br>
     *
     * The final rect width is new RectF{rect.left - shapeXOffset, top, rect.right + shapeXOffset, bottom}
     *
     * @param shapeXOffset The x-axis offset value.
     * */
    public void setShapeXOffset(float shapeXOffset) {
        this.shapeXOffset = shapeXOffset;
    }

    /**
     * Set the y-axis offset of the shape rect ({@link LighterShape#setViewRect(RectFloat)}), default is 0 <br>
     *
     * The final rect width is new RectF{rect.left, top - shapeYOffset, rect.right, bottom + shapeYOffset}
     * @param shapeYOffset The y-axis offset value.
     * */
    public void setShapeYOffset(float shapeYOffset) {
        this.shapeYOffset = shapeYOffset;
    }

    /**
     * Set the direction of the tip view relative to the highlighted view.
     * @param tipViewRelativeDirection Must be {@link Direction}
     * */
    public void setTipViewRelativeDirection(int tipViewRelativeDirection) {
        this.tipViewRelativeDirection = tipViewRelativeDirection;
    }

    /**
     * Set the offset of the tip view's margin relative to the highlighted view.
     *
     * @param marginOffset The margin offset values.
     * */
    public void setTipViewRelativeMarginOffset(MarginOffset marginOffset) {
        this.tipViewRelativeMarginOffset = marginOffset;
    }

    /**
     * Set the rect of highlighted view.
     *
     * @param highlightedViewRect highlightedViewRect
     * */
    public void setHighlightedViewRect(RectFloat highlightedViewRect) {
        this.highlightedViewRect = highlightedViewRect;
    }

    /**
     * Set animation of the tip view.
     *
     * @param tipViewDisplayAnimation tipViewDisplayAnimation
     * */
    public void setTipViewDisplayAnimation(AnimatorValue tipViewDisplayAnimation) {
        this.tipViewDisplayAnimation = tipViewDisplayAnimation;
    }

    /**
     * getHighlightedViewRect
     * @return RectFloat
     */
    public RectFloat getHighlightedViewRect() {
        return highlightedViewRect;
    }

    /**
     * 获取TipView相对方向
     * @return TipView相对方向
     */
    public int getTipViewRelativeDirection() {
        return tipViewRelativeDirection;
    }

    /**
     * getTipViewDisplayAnimation
     * @return AnimatorValue
     */
    public AnimatorValue getTipViewDisplayAnimation() {
        return tipViewDisplayAnimation;
    }

    /**
     * 获取TipView 相对位置偏移量数据
     * @return MarginOffset
     */
    public MarginOffset getTipViewRelativeMarginOffset() {
        return tipViewRelativeMarginOffset;
    }

    /**
     * getHighlightedViewId
     * @return 高亮View Id
     */
    public int getHighlightedViewId() {
        return highlightedViewId;
    }

    /**
     * 是否垂直方向自动适配
     * @return 是否垂直方向自动适配
     */
    public boolean isAutoVerticalFixed() {
        return autoVerticalFixed;
    }

    /**
     * 获取高亮显示View
     * @return 高亮Component
     */
    public Component getHighlightedView() {
        return highlightedView;
    }

    /**
     * getTipLayoutId
     * @return TipLayoutId
     */
    public int getTipLayoutId() {
        return tipLayoutId;
    }

    /**
     * 获取TipView 对象
     * @return Component
     */
    public Component getTipView() {
        return tipView;
    }

    /**
     * 获取TipView 边框显示样式
     * @return LighterShape
     */
    public LighterShape getLighterShape() {
        return lighterShape;
    }

    /**
     * X轴偏移量
     * @return shape X轴偏移量
     */
    public float getShapeXOffset() {
        return shapeXOffset;
    }

    /**
     * Y轴偏移量
     * @return  shape Y轴偏移量
     */
    public float getShapeYOffset() {
        return shapeYOffset;
    }

    /**
     * Help to build {@link LighterParameter}
     */
    public static class Builder{
        private LighterParameter mLighterParameter;

        public Builder(){
            mLighterParameter = new LighterParameter();

        }

        /**
         * 设置垂直方向自动适配
         * @param autoVerticalFixed autoVerticalFixed
         * @return Builder
         */
        public Builder setAutoVerticalFixed(boolean autoVerticalFixed) {
            mLighterParameter.setAutoVerticalFixed(autoVerticalFixed);
            return this;
        }

        /**
         * Set the id of the view that will be highlighted. <br>
         * If you use {@link Lighter#with(Ability)}, will call {@link Ability#findComponentById(int)} <br>
         * If you use {@link Lighter#with(ComponentContainer)} )}, will call {@link ComponentContainer#findComponentById(int)}
         *
         * @param highlightedViewId highlightedViewId
         * @return Builder
         * */
        public Builder setHighlightedViewId(int highlightedViewId) {
            mLighterParameter.setHighlightedViewId(highlightedViewId);
            return this;
        }

        /**
         * Set the view that will be highlighted.
         *
         * @param highlightedView The highlighted view.
         * @return Builder
         * */
        public Builder setHighlightedView(Component highlightedView) {
            mLighterParameter.setHighlightedView(highlightedView);
            return this;
        }

        /**
         * Set the layout id of the tip layout. <br>
         *
         * Will call {@link ohos.agp.components.LayoutScatter#getInstance(Context)#parse(int, ComponentContainer, boolean)} to create the
         * tip layout. <br>
         *
         * Will attached to {@link me.samlss.lighter.view.LighterView}
         *
         * @param tipLayoutId The layout id of tip.
         * @return Builder
         * */
        public Builder setTipLayoutId(int tipLayoutId) {
            mLighterParameter.setTipLayoutId(tipLayoutId);
            return this;
        }

        /**
         * Set the tip view
         *
         * Will attached to {@link me.samlss.lighter.view.LighterView}
         * @param tipView The tip view.
         * @return Builder
         * */
        public Builder setTipView(Component tipView) {
            mLighterParameter.setTipView(tipView);
            return this;
        }

        /**
         * Set the shape of the wrapped highlight view
         *
         * @param lighterShape The highlighted shape.
         * @return Builder
         * */
        public Builder setLighterShape(LighterShape lighterShape) {
            mLighterParameter.setLighterShape(lighterShape);
            return this;
        }

        /**
         * Set the x-axis offset of the shape rect({@link LighterShape#setViewRect(RectFloat)}), default is 10  <br>
         *
         * The final rect width is new RectF{rect.left - shapeXOffset, top, rect.right + shapeXOffset, bottom}
         *
         * @param xOffset The x-axis offset value.
         * @return Builder
         * */
        public Builder setShapeXOffset(float xOffset) {
            mLighterParameter.setShapeXOffset(xOffset);
            return this;
        }

        /**
         * Set the y-axis offset of the shape rect ({@link LighterShape#setViewRect(RectFloat)}), default is 10 <br>
         *
         * The final rect width is new RectF{rect.left, top - shapeYOffset, rect.right, bottom + shapeYOffset}
         * @param yOffset The y-axis offset value.
         * @return Builder
         * */
        public Builder setShapeYOffset(float yOffset) {
            mLighterParameter.setShapeYOffset(yOffset);
            return this;
        }

        /**
         * Set the direction of the tip view relative to the highlighted view.
         * @param tipViewRelativeDirection Must be {@link Direction}
         * @return Builder
         * */
        public Builder setTipViewRelativeDirection(int tipViewRelativeDirection) {
            mLighterParameter.setTipViewRelativeDirection(tipViewRelativeDirection);
            return this;
        }

        /**
         * Set the offset of the tip view's margin relative to the highlighted view.
         *
         * @param marginOffset The margin offset values.
         * @return Builder
         * */
        public Builder setTipViewRelativeOffset(MarginOffset marginOffset) {
            mLighterParameter.setTipViewRelativeMarginOffset(marginOffset);
            return this;
        }

        /**
         * Set animation of the tip view.
         * @param tipViewDisplayAnimation tipViewDisplayAnimation
         * @return Builder
         * */
        public Builder setTipViewDisplayAnimation(AnimatorValue tipViewDisplayAnimation) {
            mLighterParameter.setTipViewDisplayAnimation(tipViewDisplayAnimation);
            return this;
        }

        /**
         * build constructor
         * @return LighterParameter
         */
        public LighterParameter build(){
            return mLighterParameter;
        }
    }
}
